`
https://leetcode.cn/problems/maximum-count-of-positive-integer-and-negative-integer/
`

/**
 * @param {number[]} nums
 * @return {number}
 */
var maximumCount = function (nums) {
  // 找到正整数左边界，> 0 等价 >= 1
  const posL = lower_bound(nums, 1)
  // 找到负整数右边界 < 0 等价 (>= 0) - 1
  const negR = lower_bound(nums, 0) - 1
  // 计算各自的长度
  const posLen = nums.length - posL
  const negLen = negR + 1
  return Math.max(posLen, negLen)
};

function lower_bound(nums, target) {
  let left = 0, right = nums.length - 1
  while (left <= right) {
    const mid = left + Math.floor((right - left) / 2)
    if (nums[mid] < target) {
      left = mid + 1
    } else {
      right = mid - 1
    }
  }
  return left
}